import random
import string


def generate_password(length):
    # 生成随机length的密码，包括所有大小写字母，数字，标点符号

    # string.ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    # string.digits = '0123456789'
    # string.punctuation = '!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~'
    all_characters = string.ascii_letters + string.digits + string.punctuation
    password = ''.join(random.choice(all_characters) for i in range(length))
    return password


def generate_password_2(length):
    # 生成随机length的密码，包括所有大小写字母，数字，自定义的符号

    # string.ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    # string.digits = '0123456789'
    my_punctuation = '#$&*@'
    all_characters = string.ascii_letters + string.digits + my_punctuation
    password = ''.join(random.choice(all_characters) for i in range(length))
    return password


def generate_password_3(length):
    # 生成随机length的密码，去掉了常见字母、数字、标点符号中看上去容易混淆的字符，如l,1,I,0,o,O

    my_letters = 'abcdefghjkmnpqrtuvwxyzABCDEFGHJKLMNPQRTUVWXYZ'
    my_digits = '2346789'
    my_punctuation = '#$&*@'
    all_characters = my_letters + my_digits + my_punctuation
    password = ''.join(random.choice(all_characters) for i in range(length))
    return password


if __name__ == '__main__':
    # 设置密码长度，用户根据需要修改password_length，从3种生成方式中选择一种

    # 密码长度
    password_length = 12

    password = generate_password_3(password_length)
    print("生成的随机密码是:", password)